package cn.hznc.controller.machineTool;

import cn.hutool.http.HttpUtil;
import cn.hznc.configuration.SystemInit;
import cn.hznc.controller.service.message.MessageService;
import cn.hznc.domain.response.ResponseBody;
import cn.hznc.vo.MachineToolStatusVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @Author：Administrator
 * @Date：2023/11/13 17:22
 */
@RestController
@CrossOrigin(origins = "*", maxAge = 3600)
@RequestMapping("/machineTool")
@Slf4j
public class MachineToolController{

    public static final ConcurrentHashMap<String, Integer> statusMapping = new ConcurrentHashMap<>();

    static {
        statusMapping.put("running" , 0);
        statusMapping.put("free" , 1);
        statusMapping.put("holding" , 2);
        statusMapping.put("offline" , 4);
    }

    @RequestMapping(value = "/getStatus", method = RequestMethod.GET)
    public ResponseBody getStatus() {
        List<MachineToolStatusVo> machineToolStatusVoList = new ArrayList<>();
        SystemInit.statusMap.forEach((k ,v)->{
            MachineToolStatusVo machineToolStatusVo = new MachineToolStatusVo();
            machineToolStatusVo.setSnCode(k);
            machineToolStatusVo.setStatus(statusMapping.get(v));
            machineToolStatusVoList.add(machineToolStatusVo);
        });
        return ResponseBody.success(machineToolStatusVoList);
    }
}
